import java.awt.Color;
import java.awt.Graphics2D;
import java.util.Timer;


public class Bomb extends Entity {
	private BombStrategy strategy = new LowRangeStrategy();

	private static String imagePath = "bomberman_bomb.jpg";
	private Timer timer = SimulationRunner.getTimer();
	private User user;
	protected int bombRange;
	private boolean isExploded;
	
	public Bomb(User user) {

		super(imagePath);
		this.user=user;
		isExploded = false;
		timer.schedule(new MyTimerTask(this.user) {
			
			@Override
			public void run() {
				this.user.notifyMap(true, strategy.range);
				isExploded = true;
				SimulationRunner.setIsExploded(true);
				timer.schedule(new MyTimerTask(user) {
					@Override
					public void run() {
						SimulationRunner.setIsExploded(false);
						this.user.notifyMap(false, strategy.range);
						this.user.removeBomb();
					}
				}, 1000);
			}
		},3000);
	}

	@Override
	public void step() {
		// Do nothing
		
	}
	
	public void draw(Graphics2D g2d){
		if(isExploded){
			g2d.setColor(Color.red);
			g2d.fillRect(getX(), getY(), getEntityWidth(), getEntityHeight());
			
		} else {
			g2d.setColor(Color.black);
			g2d.fillOval(getX(), getY(), getEntityWidth(), getEntityHeight());
		}
		
	}
	
	
	public void setStrategy(BombStrategy st) {
		strategy = st;
	}
}
